package com.sjgtw.cloud.system.service.impl;

import java.util.HashSet;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sjgtw.cloud.system.api.domain.SysUser;
import com.sjgtw.cloud.system.service.ISysMenuService;
import com.sjgtw.cloud.system.service.ISysPermissionService;
import com.sjgtw.cloud.system.service.ISysRoleService;

/**
 * <p>Title: 获取用户角色、菜单权限Service实现</p>
 * <p>Description: </p>
 * @author Admin
 * @date 2021-4-8
 */
@Service
public class SysPermissionServiceImpl implements ISysPermissionService
{
    @Autowired
    private ISysRoleService roleService;

    @Autowired
    private ISysMenuService menuService;

    /**
	 * <p>Title: 根据用户ID获取角色数据权限</p>
	 * <p>Description: </p>
	 * @param userId 用户Id
	 * @return 角色权限信息
	 */
    @Override
    public Set<String> getRolePermission(Long userId)
    {
        Set<String> roles = new HashSet<String>();
        // 获取超管角色权限
        if (SysUser.isAdmin(userId))
        {
            roles.add("admin");
        }
        else
        {
            roles.addAll(roleService.selectRolePermissionByUserId(userId));
        }
        return roles;
    }

    /**
   	 * <p>Title: 根据用户ID获取菜单数据权限</p>
   	 * <p>Description: </p>
   	 * @param userId 用户Id
   	 * @return 菜单权限信息
   	 */
    @Override
    public Set<String> getMenuPermission(Long userId)
    {
        Set<String> perms = new HashSet<String>();
        // 获取超管菜单权限
        if (SysUser.isAdmin(userId))
        {
            perms.add("*:*:*");
        }
        else
        {
            perms.addAll(menuService.selectMenuPermsByUserId(userId));
        }
        return perms;
    }
}
